/**
 * All rights Reserved, Designed By junglead.cn
 * @package cn.junglead.common.utils
 * @title RegexUtil.java
 * @date 2020年8月30日
 */
package cn.junglead.common.utils;

import java.util.regex.Pattern;

/**
 * 正则表达式工具，封装一些基本常用的正则表达式验证方法
 * @author Gary.Wang
 * @version 1.0
 */
public final class RegexUtil {

	private RegexUtil(){}

	private static final String REGEX_EMAIL = "[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?";
	private static final String REGEX_INTEGER = "^[1-9]\\d*$";
	private static final String REGEX_ID_CARD = "^(\\d{6})(\\d{4})(\\d{2})(\\d{2})(\\d{3})([0-9]|X)$";
	private static final String REGEX_ZIPCODE = "[1-9]\\d{5}(?!\\d)";
	private static final String REGEX_CHINESE = "[\\u4e00-\\u9fa5]+";
	private static final String REGEX_MOBILE = "1\\d{10}";
	private static final String REGEX_CAPTCHA = "[0-9]{8}";
	
	/**
	 * 是否电子邮箱
	 * @param email，电子邮箱
	 * @return 返回是否匹配
	 */
	public static boolean isEmail(String email){
        return Pattern.matches(REGEX_EMAIL, email);
	}
	
	/**
	 * 是否手机号码
	 * @param mobile，要匹配的手机号码
	 * @return 返回是否匹配
	 */
	public static boolean isMobile(String mobile){
		return Pattern.matches(REGEX_MOBILE, mobile);
	}
	
	/**
	 * 是否整数
	 * @param number，整数字符串
	 * @return 返回是否匹配
	 */
	public static boolean isInteger(String number){
		return Pattern.matches(REGEX_INTEGER, number);
	}
	
	/**
	 * 是否身份证号码
	 * @param idCard，身份证号码
	 * @return 返回是否匹配
	 */
	public static boolean isIdCard(String idCard){
		return Pattern.matches(REGEX_ID_CARD, idCard);
	}
	
	/**
	 * 是否邮政编码
	 * @param zipcode，邮政编码
	 * @return 返回是否匹配
	 */
	public static boolean isZipcode(String zipcode){
		return Pattern.matches(REGEX_ZIPCODE, zipcode);
	}
	
	/**
	 * 是否中文
	 * @param chinese，中文
	 * @return 返回是否匹配
	 */
	public static boolean isChinese(String chinese){
		return Pattern.matches(REGEX_CHINESE, chinese);
	}
	
	/**
	 * 是否验证码
	 * @param captcha 验证码
	 * @return 返回验证结果
	 */
	public static boolean isCaptcha(String captcha) {
		return Pattern.matches(REGEX_CAPTCHA, captcha);
	}
}
